\section{solve --- Linear Equation Solution}
\label{fn:solve}
\index{solve()}
\index{linear equation solution}
\index{solution of linear equations}
\begin{rail}
Solve : 'solve' '(' Matrix ',' Matrix ')' ;
\end{rail}

\verb+solve+ is a function to find the solution to sets of
linear equations. If the linear equation is of the form:

\[ A x = B \]

then $A$ is the first argument to solve, and is the square,
non-singular, co-efficients matrix.  Each column in the second
argument is used in turn as the constant part, $B$, and the each
column in the resulting matrix corresponds to using the same
column of $B$ as the right hand side.

The idea behind this is that you may have a several sets of linear
equations using the same co-efficients with each variable, but
equated to different constants.  Since most of the work is associated
with the variable co-efficients, it adds little overhead to solve for
several sets of constants, at the same time. Not withstanding this,
most of the time both the second argument and the result will be
column vectors, representing a set of simultaneous solutions.


\paragraph{Example}
\index{example of solve()}
\index{solve()!example}
\begin{verbatim}
> A = rand(5,5)
 A =
   0.0882    0.00543      0.246      0.161      0.555
    0.908      0.222      0.782      0.975       0.29
    0.362       0.98      0.341     0.0106      0.205
    0.148       0.83      0.461      0.414      0.561
    0.879    0.00526       0.52      0.233      0.791
> X = rand(5,1)
 X =
    0.269
    0.334
    0.278
    0.789
    0.692
> B = A*X
 B =
    0.605
     1.51
     0.67
     1.16
     1.11
> //Now we should be able to use A and B to get X back
> soln = solve(A,B)
 soln =
    0.269
    0.334
    0.278
    0.789
    0.692
> // Check how close we are:
> soln - X
-2.22e-16
-1.67e-16
 8.88e-16
-4.44e-16
-2.22e-16
\end{verbatim}

See also: Page~\pageref{fn:backsub} \verb+backsub()+,
Page~\pageref{fn:factor} \verb+factor()+,
Page~\pageref{fn:inv} \verb+inv()+.


\newpage



